// pages/todoList/modal/modal.js
Component({
  properties: {
    isShow: {  //是否显示modal
      type: Boolean,
      value: false,
    }
  },
  data: {
    name: '',
    time: ''
  },
  methods: {
    inputName(e){
      this.setData({ name: e.detail.value })
    },
    inputTime(e) {
      let time = e.detail.value
      if(time!=0 && Object.is(parseInt(time), NaN)) {  //ES6新语法
        wx.showToast({
          title: '时间格式不规范',
          icon: 'none'
        })
        this.setData({
          time: ''
        })
        return 
      }else {
        time = parseInt(time)
        this.setData({ time: time })    
      }
    },
    confirm() {
      let name = this.data.name
      let time = this.data.time
      if( this.data.name == '') {
        wx.showToast({
          title: '待办名不得为空',
          icon: 'none'
        })
        this.setData({time})
      }else if(this.data.time > 60 || this.data.time <= 0 || this.data.time == '' ) {
        wx.showToast({
          title: '请输入小于60分钟的专注时间',
          icon: 'none'
        })
        this.setData({name})
      }else {
        let event = {name: name, time: time}
        this.triggerEvent('confirm', event)
        this.setData({
          name: '',
          time: ''
        })
      }
    },
    cancel() {
      this.triggerEvent('cancel')
      this.setData({
        name: '',
        time: ''
      })
    },
  },
  
})
